#!/bin/bash

JDK_DOWNLOAD_URL="https://repo.huaweicloud.com/java/jdk/8u151-b12/"

JDK_FILE_NAME="jdk-8u151-linux-x64.tar.gz"

INSTALL_PATH="/usr/local/"

JDK_NAME="jdk1.8.0_151"

#echo ${INSTALL_PATH}${JDK_FILE_NAME}  $INSTALL_PATH
#exit 

#---------------------------------------------
if [ ! -e ${INSTALL_PATH}${JDK_FILE_NAME} ]

then

echo "开始下载jdk"

wget ${JDK_DOWNLOAD_URL}${JDK_FILE_NAME} -P $INSTALL_PATH

fi

#---------------------------------------------
if [ ! -e ${INSTALL_PATH}${JDK_NAME}  ]

then

echo "开始解压jdk"

tar -zxvf ${INSTALL_PATH}${JDK_FILE_NAME} -C  ${INSTALL_PATH}

echo "解压完毕"

echo "删除JDK安装包"

rm -rf ${INSTALL_PATH}${JDK_FILE_NAME} 

fi
#---------------------------------------------

#exit

echo  "开始设置环境变量"

echo "#java环境变量开始" >> /etc/profile
JAVA_HOME=${INSTALL_PATH}${JDK_NAME}
PATH=${JAVA_HOME}/bin:${PATH}
CLASSPATH=.:${JAVA_HOME}/lib/dt.jar:${JAVA_HOME}/lib.tools.jar

echo  JAVA_HOME=$JAVA_HOME  >> /etc/profile
echo  PATH=$PATH >> /etc/profile
echo  CLASSPATH=$CLASSPATH >> /etc/profile
echo  export JAVA_HOME CLASSPATH PATH >> /etc/profile
echo  "#java环境变量结束" >> /etc/profile


#echo "使环境变量生效"
#source /etc/profile

echo "配置java环境成功,请使用java命令测试环境"


# 使用文档
# wget https://gitee.com/yaolliuyang/linux_shell/raw/master/installJdk1.8.sh -O installJdk1.8.sh && chmod a+x installJdk1.8.sh && source installJdk1.8.sh














